package com.lz.ionicbase.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lz.ionicbase.R;
import com.lz.ionicbase.ui.activity.BaseWebViewActivity;
import com.lz.ionicbase.ui.fragment.event.MiddleEvent;
import com.lz.ionicbase.ui.fragment.event.SmallEvent;
import com.lz.ionicbase.ui.fragment.event.WeightEvent;
import com.lz.ionicbase.utils.SpUtils;
import com.lz.ionicbase.utils.ToastUtils;
import com.lz.ionicbase.view.MyViewPager;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * Created by lenovo on 2017/2/4.
 */
public class WorkFragment extends Fragment {

    @InjectView(R.id.workViewPager)
    MyViewPager myViewPager;
    @InjectView(R.id.work_recyclerview)
    RecyclerView workRecyclerview;
    private SpUtils sp;
    private String netUrl;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_work, null);
        ButterKnife.inject(this, view);
        EventBus.getDefault().register(this);
        initView();
        return view;
    }

    private void initView() {
        sp = new SpUtils();
    }

    private void initData() {

    }

    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onSmallEvent(SmallEvent event) {
        /* Do something */
        String msg = event.getMsg();
        ToastUtils.showToast(getActivity(),msg,0);
        Intent intent = new Intent(getActivity(), BaseWebViewActivity.class);
        intent.putExtra("url",netUrl+msg);
        startActivity(intent);
    };
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onMiddleEvent(MiddleEvent event) {
        /* Do something */
        String msg = event.getMsg();
        ToastUtils.showToast(getActivity(),msg,0);
        Intent intent = new Intent(getActivity(), BaseWebViewActivity.class);
        intent.putExtra("url",netUrl+msg);
        startActivity(intent);
    };
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onWeightEvent(WeightEvent event) {
        /* Do something */
        String msg = event.getMsg();
        ToastUtils.showToast(getActivity(),msg,0);
        Intent intent = new Intent(getActivity(), BaseWebViewActivity.class);
        intent.putExtra("url",netUrl+msg);
        startActivity(intent);
    };

    @Override
    public void onStart() {
        super.onStart();
        initData();
    }

    @Override
    public void onStop() {
        super.onStop();
        myViewPager.setCancleHandle();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }
}


